﻿// BigInteger.cpp - 大整数库主逻辑。
// Written by Xiaoxuan4096.

// Code in this file is restricted by the license of the whole program.
// See LICENSE.txt for further information.

#include "pch.h"
#include "BigInteger.h"

namespace Xiaoxuan4096 {
	namespace PreciseNumbers {
		// Set the number...
		template<typename T> inline void BigIntegerT<T>::operator=(std::string number) { // ... by a string.
			std::string tmpNumber = "";
			nums.clear();
			for (size_t i = number.size() - 1; i >= 0; ) {
				// Step 1: Split the string from the end to the front by given length.
				for (size_t count = 0; count <= digitLength && i >= 0; count++) {
					tmpNumber = tmpNumber + number[i--];
				}

				// Step 2: Convert to numbers and add to the front of the vector.
				std::stringstream ss;
				T num;
				ss << tmpNumber;
				ss >> num;
				nums.insert(nums.begin(), num);
			}
			return;
		}
		template<typename T> template<typename N> inline void BigIntegerT<T>::operator=(N number) { // ... by a number.
			std::stringstream ss;
			std::string tmp;
			ss << number;
			ss >> tmp;
			operator=(tmp);
			return;
		}

		// Utilities.
		template<typename T> std::string BigIntegerT<T>::convertToString() {
			std::string numberString;
			for (auto x : nums) {
				std::stringstream ss;
				std::string tmp;
				ss << x;
				ss >> tmp;
				numberString += tmp;
			}
			return numberString;
		}

		// Basic operations.
		template<typename T> template<typename Ta> inline void BigIntegerT<T>::operator+=(BigIntegerT<Ta> a) {
			BigIntegerT<T> btmp = a.convertToString();
			if (!(a.negative ^ negative)) {
				operator-=(a);
				return;
			}
			
		}
		template<typename T> template<typename Ta> inline void BigIntegerT<T>::operator-=(BigIntegerT<Ta> a) {
		}
	}
}
